package com.chen.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chen.entity.ExamHistory;
import com.chen.vo.ExamHistoryPaperVO;
import com.chen.vo.ExamHistoryVO;

import java.util.List;

/**
 * 考试历史记录
 */
public interface ExamHistoryMapper extends BaseMapper<ExamHistory> {

    /**
     * 通过学生id和时间编号查询考试记录条数
     * 意在于避免考生重复考试
     *
     * @param studentId
     * @param examPaperId
     * @return
     */
    default Long findCountByStudentIdAndExamPaperId(Integer studentId, Integer examPaperId) {
        Wrapper<ExamHistory> queryWrapper = Wrappers.lambdaQuery(ExamHistory.class).eq(ExamHistory::getStudentId, studentId).eq(ExamHistory::getExamPaperId, examPaperId);
        return selectCount(queryWrapper);
    }

    /**
     * 根据学生id查找该学生的考试记录信息
     *
     * @param studentId
     * @return
     */
    List<ExamHistoryPaperVO> findExamHistoryByStudentId(Integer studentId);


    /**
     * 根据试卷id删除
     *
     * @param examPaperId
     * @return
     */
    default Integer deleteByExamPaperId(Integer examPaperId) {
        Wrapper<ExamHistory> updateWrapper = Wrappers.lambdaUpdate(ExamHistory.class).eq(ExamHistory::getExamPaperId, examPaperId);
        return delete(updateWrapper);
    }

    /**
     * 考试记录
     * @return
     */
    public List<ExamHistoryVO> findExamHistoryList();

}
